{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Azure ML SDK Version:  1.3.0\n"
     ]
    }
   ],
   "source": [
    "import azureml\n",
    "from azureml.core import Workspace\n",
    "\n",
    "# check core SDK version number\n",
    "print(\"Azure ML SDK Version: \", azureml.core.VERSION)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Workspace name: trialws3\n",
      "Azure region: eastus\n",
      "Subscription id: cb4187b1-dbe9-459d-a2f7-dfa57764a96f\n",
      "Resource group: trialws3\n"
     ]
    }
   ],
   "source": [
    "ws = Workspace.from_config()\n",
    "print('Workspace name: ' + ws.name, \n",
    "      'Azure region: ' + ws.location, \n",
    "      'Subscription id: ' + ws.subscription_id, \n",
    "      'Resource group: ' + ws.resource_group, sep='\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from azureml.core.dataset import Dataset\n",
    "\n",
    "dataset_paths = [\n",
    "    'https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_idle.txt',\n",
    "    'https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_idle_2.txt',\n",
    "    'https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_working.txt',\n",
    "    'https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_working_2.txt'\n",
    "]\n",
    "\n",
    "dataset = Dataset.File.from_files(path = dataset_paths)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset_registered = False\n",
    "try:\n",
    "    temp = Dataset.get_by_name(workspace=ws, name='motor_activity_recognition')\n",
    "    dataset_registered = True\n",
    "except:\n",
    "    print(\"The dataset motor activity is not registered in workspace yet.\")\n",
    "\n",
    "if not dataset_registered:\n",
    "    dataset = dataset.register(workspace = ws,\n",
    "                               name = 'motor_activity_recognition',\n",
    "                               description='training and test dataset for motor activity recognition',\n",
    "                               create_new_version=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c1ds2v2 ComputeInstance Succeeded\n"
     ]
    }
   ],
   "source": [
    "compute_targets = ws.compute_targets\n",
    "for name, ct in compute_targets.items():\n",
    "    print(name, ct.type, ct.provisioning_state)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/https/raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_idle.txt',\n",
       " '/https/raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_idle_2.txt',\n",
       " '/https/raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_working.txt',\n",
       " '/https/raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_working_2.txt']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset = Dataset.get_by_name(ws, 'motor_activity_recognition')\n",
    "\n",
    "# list the files referenced by mnist dataset\n",
    "dataset.to_path()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_folder = dataset.as_named_input('motor_activity').as_mount()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_folder.dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from azureml.core import Experiment\n",
    "\n",
    "script_folder = './motor-activity-recognition'\n",
    "os.makedirs(script_folder, exist_ok=True)\n",
    "\n",
    "exp = Experiment(workspace=ws, name='motor-activity-recognition-2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'./motor-activity-recognition/tfkeras-train-model.py'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import shutil\n",
    "\n",
    "# the training logic is in the keras_mnist.py file.\n",
    "shutil.copy('./tfkeras-train-model.py', script_folder)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from azureml.core.runconfig import RunConfiguration\n",
    "from azureml.core.environment import CondaDependencies\n",
    "from azureml.core import Environment\n",
    "\n",
    "env = Environment(name=\"motor_activity_env\")\n",
    "env.docker.enabled = True\n",
    "\n",
    "conda_dep = CondaDependencies()\n",
    "conda_dep.add_pip_package(\"scipy\")\n",
    "conda_dep.add_pip_package(\"scikit-learn\")\n",
    "conda_dep.add_pip_package(\"pandas\")\n",
    "conda_dep.add_pip_package(\"numpy==1.16.2\")\n",
    "conda_dep.add_pip_package(\"matplotlib==3.0.3\")\n",
    "conda_dep.add_pip_package(\"tensorflow==2.1.0\")\n",
    "\n",
    "env.python.conda_dependencies = conda_dep\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "from azureml.core import ScriptRunConfig\n",
    "\n",
    "\n",
    "script_params = [\n",
    "    '--data-folder', dataset.as_named_input('motor_activity').as_mount(),\n",
    "    '--batch-size', 50,\n",
    "    '--n-fc-layer', 128,\n",
    "    '--dropout-ratio', 0.1,\n",
    "    '--learning-rate', 0.1\n",
    "]\n",
    "\n",
    "src = ScriptRunConfig(source_directory=script_folder,\n",
    "                      script='tfkeras-train-model.py',\n",
    "                      arguments=script_params)\n",
    "src.run_config.environment = env\n",
    "src.run_config.target = compute_targets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "run = exp.submit(src)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4479ccf1e3e549498a8b74a3d7185e00",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "_UserRunWidget(widget_settings={'childWidgetDisplay': 'popup', 'send_telemetry': False, 'log_level': 'INFO', '…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/aml.mini.widget.v1": "{\"status\": \"Completed\", \"workbench_run_details_uri\": \"https://ml.azure.com/experiments/motor-activity-recognition-2/runs/motor-activity-recognition-2_1587804446_be2a7838?wsid=/subscriptions/cb4187b1-dbe9-459d-a2f7-dfa57764a96f/resourcegroups/trialws3/workspaces/trialws3\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"run_properties\": {\"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"created_utc\": \"2020-04-25T08:47:26.727135Z\", \"properties\": {\"_azureml.ComputeTargetType\": \"local\", \"ContentSnapshotId\": \"bdf27341-0e59-412f-88f6-be33e59f2280\"}, \"tags\": {}, \"script_name\": null, \"arguments\": null, \"end_time_utc\": \"2020-04-25T08:48:10.234094Z\", \"status\": \"Completed\", \"log_files\": {\"azureml-logs/60_control_log.txt\": \"https://trialws34689768129.blob.core.windows.net/azureml/ExperimentRun/dcid.motor-activity-recognition-2_1587804446_be2a7838/azureml-logs/60_control_log.txt?sv=2019-02-02&sr=b&sig=GCEKfZjBGpe6fzma0CzC8bMbgmyfAVzOhba6eNDyh4U%3D&st=2020-04-25T08%3A38%3A28Z&se=2020-04-25T16%3A48%3A28Z&sp=r\", \"azureml-logs/70_driver_log.txt\": \"https://trialws34689768129.blob.core.windows.net/azureml/ExperimentRun/dcid.motor-activity-recognition-2_1587804446_be2a7838/azureml-logs/70_driver_log.txt?sv=2019-02-02&sr=b&sig=6L%2F1Mpt8p4d3F0FBC72R9JJkhtZzCF34V0fAbkeQpN4%3D&st=2020-04-25T08%3A38%3A29Z&se=2020-04-25T16%3A48%3A29Z&sp=r\", \"logs/azureml/9_azureml.log\": \"https://trialws34689768129.blob.core.windows.net/azureml/ExperimentRun/dcid.motor-activity-recognition-2_1587804446_be2a7838/logs/azureml/9_azureml.log?sv=2019-02-02&sr=b&sig=B8iu2b57pIwwrIZc%2BBtQHL4JG3qx3eR16XZXLpENzUM%3D&st=2020-04-25T08%3A38%3A28Z&se=2020-04-25T16%3A48%3A28Z&sp=r\"}, \"log_groups\": [[\"logs/azureml/9_azureml.log\"], [\"azureml-logs/60_control_log.txt\"], [\"azureml-logs/70_driver_log.txt\"]], \"run_duration\": \"0:00:43\"}, \"child_runs\": [], \"children_metrics\": {}, \"run_metrics\": [{\"name\": \"Loss\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], \"series\": [{\"data\": [0.676260283130692, 0.6599792451728376, 0.6521811946221063, 0.6335287824374786, 0.40939468353241115, 0.5015582376985138, 0.5881581037129481, 0.3705503904430861, 0.334139343370896, 0.280016592183377, 0.2603692585451301, 0.30582299455717893, 0.23937289811066373, 0.21718560414525756, 0.1939794530158607, 0.17341060713893813, 0.14224649051810143, 0.12282128673868707, 0.10617862999371455, 0.08940447277761572, 0.07442097740644664, 0.06903191915712545, 0.07888600685216424, 0.06412934640689362, 0.061600594109854884, 0.05434210631513433, 0.06415401638638711, 0.051764206568215544, 0.045324089899489696, 0.046559846744653036, 0.04527882198217784, 0.040558021686479755, 0.04052659347328591, 0.036230700227507504, 0.03835142911372987, 0.03627442245013656, 0.03189362493400844, 0.03283049058313167, 0.030160614874685597, 0.028626729818971842, 0.029452577981055685, 0.031248304435815253, 0.028430151405735075, 0.029358142413554812, 0.028251725459404974, 0.02448397580890085, 0.0245975879613392, 0.024232287159001765, 0.023107045621719207, 0.023371263606992067, 0.02310394129304214, 0.021973208899216456, 0.021831971210857587, 0.017326209713564373, 0.022781846606348435, 0.018067847995244253, 0.01693134919907601, 0.019984275443653114, 0.017121952177124936, 0.015557444308424782, 0.01776881935251446, 0.015427127988886164, 0.014510612686286829, 0.015161357630803967, 0.012698323552025775, 0.011694463920285975, 0.01196511880578678, 0.012376137090517861, 0.011670666743617808, 0.01926175225702615, 0.01852157880277447, 0.02004727385683978, 0.016656511309828505, 0.01717131608289365, 0.009768080732582519, 0.009472900247476695, 0.00855019105329313, 0.008575561346762996, 0.00855770577811456, 0.013847211317580767, 0.015159989112650606, 0.013074027891945126, 0.0128525572241488, 0.010881339910512874, 0.012490676497084522, 0.0061929455247458414, 0.004716702315736057, 0.004611126210228445, 0.006652930104053686, 0.004402141207320739, 0.004662917564687312, 0.0037307236235944656, 0.00371132161790594, 0.002815863151379336, 0.008261963678135554, 0.008401740039645823, 0.0073684346672819, 0.006009800634714065, 0.006990422521099319, 0.007347095625817852]}]}, {\"name\": \"Accuracy\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], \"series\": [{\"data\": [0.6065201163291931, 0.6307808756828308, 0.6315390467643738, 0.6671720743179321, 0.8514025807380676, 0.6338135004043579, 0.7710386514663696, 0.8794541358947754, 0.8931008577346802, 0.9006823301315308, 0.9075056910514832, 0.9120545983314514, 0.9143290519714355, 0.9158453345298767, 0.9742228984832764, 0.952994704246521, 0.9181197881698608, 0.9158453345298767, 0.9795299172401428, 0.9810462594032288, 0.9833207130432129, 0.9802880883216858, 0.981804370880127, 0.9825625419616699, 0.9833207130432129, 0.9825625419616699, 0.9863532781600952, 0.9893859028816223, 0.9893859028816223, 0.9886277318000793, 0.9893859028816223, 0.9871114492416382, 0.9901440739631653, 0.9871114492416382, 0.9886277318000793, 0.9893859028816223, 0.9924185276031494, 0.9909021854400635, 0.9909021854400635, 0.9916603565216064, 0.9931766390800476, 0.9931766390800476, 0.9916603565216064, 0.9931766390800476, 0.9939348101615906, 0.9916603565216064, 0.9924185276031494, 0.9924185276031494, 0.9939348101615906, 0.9924185276031494, 0.9931766390800476, 0.9931766390800476, 0.9931766390800476, 0.9954510927200317, 0.9946929216384888, 0.9946929216384888, 0.9946929216384888, 0.9946929216384888, 0.9954510927200317, 0.9962092638015747, 0.9954510927200317, 0.9946929216384888, 0.9977255463600159, 0.9969673752784729, 0.9962092638015747, 0.9962092638015747, 0.9969673752784729, 0.9962092638015747, 0.9969673752784729, 0.9954510927200317, 0.9954510927200317, 0.9946929216384888, 0.9954510927200317, 0.9954510927200317, 0.9984837174415588, 0.9984837174415588, 0.9984837174415588, 0.9984837174415588, 0.9977255463600159, 0.9946929216384888, 0.9954510927200317, 0.9962092638015747, 0.9954510927200317, 0.9962092638015747, 0.9969673752784729, 0.999241828918457, 0.999241828918457, 0.999241828918457, 0.9984837174415588, 0.999241828918457, 1, 0.999241828918457, 1, 1, 0.9977255463600159, 0.9984837174415588, 0.9984837174415588, 0.9977255463600159, 0.999241828918457, 0.9984837174415588]}]}, {\"name\": \"Validation Loss\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], \"series\": [{\"data\": [0.9792581760522091, 1.053719744537816, 0.6155905741633791, 0.7539982506723115, 0.4362773353403265, 0.47739388906594477, 1.1633500799988254, 0.35431781682101166, 0.23065076000762708, 0.18144442637761435, 0.3885724996075486, 0.2534040280363776, 0.17426746135408228, 0.1803847962256634, 0.11938703195615248, 0.08977720739715027, 0.09562622259060542, 0.09052363591212215, 0.07094440518906622, 0.07000878193613255, 0.021888827580507055, 0.036453517097415344, 0.04321038322241017, 0.019697065380486576, 0.02710187184680818, 0.009434387458234349, 0.024404652007488592, 0.019496666429790133, 0.0205871036212722, 0.008040239240720191, 0.02120796342338012, 0.015734056578807984, 0.01738254368926088, 0.020788148482979246, 0.019545726686236307, 0.016887469439428638, 0.016364387077787382, 0.009476875484159047, 0.015126364763339305, 0.009966822558040307, 0.01180729171116554, 0.010397641445293133, 0.011628149209586396, 0.010499546180874335, 0.014170360949003336, 0.013968534248168438, 0.00916353175588566, 0.01227360321177967, 0.011382754756072465, 0.00754329362010167, 0.010666615326706298, 0.01063240430614149, 0.010316039118179382, 0.0126416416438367, 0.010629017845503491, 0.006867915879741882, 0.008638449181903112, 0.006111389591806625, 0.008224393647679157, 0.009843894208450254, 0.00634771633066879, 0.009306383890472, 0.008466956915016812, 0.008052695587387214, 0.005736986334258373, 0.00475456230814223, 0.00454284057562318, 0.002428578218700061, 0.004013479783349216, 0.00740292357460765, 0.009755091331691912, 0.009894098208998472, 0.008569765015911826, 0.008674835745103226, 0.00195499842100782, 0.0022642023152112606, 0.003280638743297349, 0.0033437667622517133, 0.002699875358358082, 0.005054063349041716, 0.006243720294040748, 0.005624743714206764, 0.006774739589728239, 0.006441192018180366, 0.0051798782419747585, 0.0004461968941348349, 0.0008209139734087026, 0.0007827260401840745, 0.00045472666846707756, 0.0010569671609173934, 0.00032953541760820593, 0.0001773725719458801, 0.0002764264354206689, 0.0002330588447972387, 0.0027558745249266258, 0.0032729423431770888, 0.0022517364868139284, 0.006383184844515089, 0.0015959009204820948, 0.0014350503239587522]}]}, {\"name\": \"Validation Accuracy\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], \"series\": [{\"data\": [0.0, 0.8878787755966187, 0.3606060743331909, 0.8636363744735718, 0, 0, 0.8666666746139526, 0.903030276298523, 0.9151515364646912, 0.9575757384300232, 0.9757575988769531, 0.978787899017334, 0.9757575988769531, 0.978787899017334, 0.9818181991577148, 0.9818181991577148, 0.9818181991577148, 0.9818181991577148, 0.9818181991577148, 0.9848484992980957, 0.9939393997192383, 0.9818181991577148, 0.9939393997192383, 0.9818181991577148, 0.9939393997192383, 0.9878787994384766, 0.9939393997192383, 0.9909090995788574, 0.9878787994384766, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9909090995788574, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9969696998596191, 1, 0.9969696998596191, 0.9939393997192383, 0.9969696998596191, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 1, 1, 1, 1, 1, 0.9939393997192383, 0.9939393997192383, 0.9939393997192383, 0.9969696998596191, 0.9969696998596191, 0.9939393997192383, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9939393997192383, 1]}]}, {\"name\": \"Final test loss\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0], \"series\": [{\"data\": [0.005438241473760299]}]}, {\"name\": \"Final test accuracy\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0], \"series\": [{\"data\": [1.0]}]}, {\"name\": \"Accuracy vs Loss\", \"run_id\": \"motor-activity-recognition-2_1587804446_be2a7838\", \"categories\": [0], \"series\": [{\"data\": [\"aml://artifactId/ExperimentRun/dcid.motor-activity-recognition-2_1587804446_be2a7838/Accuracy vs Loss_1587804484.png\"]}]}], \"run_logs\": \"Initialize DatasetContextManager.\\nStarting the daemon thread to refresh tokens in background for process with pid = 9\\nSet Dataset motor_activity's target path to /tmp/tmpgo81zb8r\\nEnter __enter__ of DatasetContextManager\\nSDK version: azureml-core==1.3.0.post2 azureml-dataprep==1.4.3\\nProcessing 'motor_activity'\\nProcessing dataset FileDataset\\n{\\n  \\\"source\\\": [\\n    \\\"https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_idle.txt\\\",\\n    \\\"https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_idle_2.txt\\\",\\n    \\\"https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_working.txt\\\",\\n    \\\"https://raw.githubusercontent.com/alwint3r/Motor-Activity-Detection-TinyML/master/output_label_working_2.txt\\\"\\n  ],\\n  \\\"definition\\\": [\\n    \\\"GetFiles\\\"\\n  ],\\n  \\\"registration\\\": {\\n    \\\"id\\\": \\\"37c62e62-6d4d-48b9-900a-52ad123873a3\\\",\\n    \\\"name\\\": \\\"motor_activity_recognition\\\",\\n    \\\"version\\\": 1,\\n    \\\"description\\\": \\\"training and test dataset for motor activity recognition\\\",\\n    \\\"workspace\\\": \\\"Workspace.create(name='trialws3', subscription_id='cb4187b1-dbe9-459d-a2f7-dfa57764a96f', resource_group='trialws3')\\\"\\n  }\\n}\\nMounting motor_activity to /tmp/tmpgo81zb8r\\nMounted motor_activity to /tmp/tmpgo81zb8r\\nExit __enter__ of DatasetContextManager\\nEntering Run History Context Manager.\\nPreparing to call script [ tfkeras-train-model.py ] with arguments: ['--data-folder', '$motor_activity', '--batch-size', '50', '--n-fc-layer', '128', '--dropout-ratio', '0.1', '--learning-rate', '0.1']\\nAfter variable expansion, calling script [ tfkeras-train-model.py ] with arguments: ['--data-folder', '/tmp/tmpgo81zb8r', '--batch-size', '50', '--n-fc-layer', '128', '--dropout-ratio', '0.1', '--learning-rate', '0.1']\\n\\n2020-04-25 08:47:35.790665: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /azureml-envs/azureml_57b473d9ed2a84457992ce08ab821870/lib/python3.6/site-packages/dotnetcore2/bin/deps\\n2020-04-25 08:47:35.790766: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /azureml-envs/azureml_57b473d9ed2a84457992ce08ab821870/lib/python3.6/site-packages/dotnetcore2/bin/deps\\n2020-04-25 08:47:35.790780: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.\\nTensorflow version: 2.1.0\\ntraining dataset is stored here: /tmp/tmpgo81zb8r\\nTrain X shape: (1649, 100, 3, 1)\\nTrain Y shape: (1649, 2)\\n2020-04-25 08:47:45.650856: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /azureml-envs/azureml_57b473d9ed2a84457992ce08ab821870/lib/python3.6/site-packages/dotnetcore2/bin/deps\\n2020-04-25 08:47:45.650883: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)\\n2020-04-25 08:47:45.650908: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (053557a0c8e4): /proc/driver/nvidia/version does not exist\\n2020-04-25 08:47:45.651075: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA\\n2020-04-25 08:47:45.657164: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2294685000 Hz\\n2020-04-25 08:47:45.657303: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55fd7347f390 initialized for platform Host (this does not guarantee that XLA will be used). Devices:\\n2020-04-25 08:47:45.657323: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version\\nModel: \\\"sequential\\\"\\n_________________________________________________________________\\nLayer (type)                 Output Shape              Param #   \\n=================================================================\\nconv2d (Conv2D)              (None, 100, 3, 16)        80        \\n_________________________________________________________________\\nmax_pooling2d (MaxPooling2D) (None, 50, 1, 16)         0         \\n_________________________________________________________________\\ndropout (Dropout)            (None, 50, 1, 16)         0         \\n_________________________________________________________________\\nflatten (Flatten)            (None, 800)               0         \\n_________________________________________________________________\\ndense (Dense)                (None, 128)               102528    \\n_________________________________________________________________\\ndropout_1 (Dropout)          (None, 128)               0         \\n_________________________________________________________________\\ndense_1 (Dense)              (None, 2)                 258       \\n=================================================================\\nTotal params: 102,866\\nTrainable params: 102,866\\nNon-trainable params: 0\\n_________________________________________________________________\\nTrain on 1319 samples, validate on 330 samples\\nEpoch 1/100\\n1319/1319 - 1s - loss: 0.6763 - accuracy: 0.6065 - val_loss: 1.1634 - val_accuracy: 0.0000e+00\\nEpoch 2/100\\n1319/1319 - 0s - loss: 0.6600 - accuracy: 0.6308 - val_loss: 0.9793 - val_accuracy: 0.0000e+00\\nEpoch 3/100\\n1319/1319 - 0s - loss: 0.6522 - accuracy: 0.6315 - val_loss: 1.0537 - val_accuracy: 0.0000e+00\\nEpoch 4/100\\n1319/1319 - 0s - loss: 0.6335 - accuracy: 0.6338 - val_loss: 0.6156 - val_accuracy: 0.8879\\nEpoch 5/100\\n1319/1319 - 0s - loss: 0.5882 - accuracy: 0.6672 - val_loss: 0.7540 - val_accuracy: 0.3606\\nEpoch 6/100\\n1319/1319 - 0s - loss: 0.5016 - accuracy: 0.7710 - val_loss: 0.4774 - val_accuracy: 0.8667\\nEpoch 7/100\\n1319/1319 - 0s - loss: 0.4094 - accuracy: 0.8514 - val_loss: 0.4363 - val_accuracy: 0.8636\\nEpoch 8/100\\n1319/1319 - 0s - loss: 0.3706 - accuracy: 0.8795 - val_loss: 0.3886 - val_accuracy: 0.9030\\nEpoch 9/100\\n1319/1319 - 0s - loss: 0.3341 - accuracy: 0.8931 - val_loss: 0.3543 - val_accuracy: 0.9152\\nEpoch 10/100\\n1319/1319 - 0s - loss: 0.3058 - accuracy: 0.9007 - val_loss: 0.2534 - val_accuracy: 0.9576\\nEpoch 11/100\\n1319/1319 - 0s - loss: 0.2800 - accuracy: 0.9075 - val_loss: 0.2307 - val_accuracy: 0.9758\\nEpoch 12/100\\n1319/1319 - 0s - loss: 0.2604 - accuracy: 0.9121 - val_loss: 0.1814 - val_accuracy: 0.9788\\nEpoch 13/100\\n1319/1319 - 0s - loss: 0.2394 - accuracy: 0.9143 - val_loss: 0.1743 - val_accuracy: 0.9758\\nEpoch 14/100\\n1319/1319 - 0s - loss: 0.2172 - accuracy: 0.9158 - val_loss: 0.1804 - val_accuracy: 0.9788\\nEpoch 15/100\\n1319/1319 - 0s - loss: 0.1940 - accuracy: 0.9158 - val_loss: 0.1194 - val_accuracy: 0.9818\\nEpoch 16/100\\n1319/1319 - 0s - loss: 0.1734 - accuracy: 0.9181 - val_loss: 0.0956 - val_accuracy: 0.9818\\nEpoch 17/100\\n1319/1319 - 0s - loss: 0.1422 - accuracy: 0.9530 - val_loss: 0.0905 - val_accuracy: 0.9818\\nEpoch 18/100\\n1319/1319 - 0s - loss: 0.1228 - accuracy: 0.9742 - val_loss: 0.0898 - val_accuracy: 0.9818\\nEpoch 19/100\\n1319/1319 - 0s - loss: 0.1062 - accuracy: 0.9795 - val_loss: 0.0709 - val_accuracy: 0.9818\\nEpoch 20/100\\n1319/1319 - 0s - loss: 0.0894 - accuracy: 0.9803 - val_loss: 0.0700 - val_accuracy: 0.9818\\nEpoch 21/100\\n1319/1319 - 0s - loss: 0.0789 - accuracy: 0.9810 - val_loss: 0.0365 - val_accuracy: 0.9848\\nEpoch 22/100\\n1319/1319 - 0s - loss: 0.0744 - accuracy: 0.9833 - val_loss: 0.0432 - val_accuracy: 0.9818\\nEpoch 23/100\\n1319/1319 - 0s - loss: 0.0690 - accuracy: 0.9826 - val_loss: 0.0219 - val_accuracy: 0.9939\\nEpoch 24/100\\n1319/1319 - 0s - loss: 0.0641 - accuracy: 0.9818 - val_loss: 0.0197 - val_accuracy: 0.9939\\nEpoch 25/100\\n1319/1319 - 0s - loss: 0.0616 - accuracy: 0.9833 - val_loss: 0.0271 - val_accuracy: 0.9879\\nEpoch 26/100\\n1319/1319 - 0s - loss: 0.0543 - accuracy: 0.9894 - val_loss: 0.0094 - val_accuracy: 0.9939\\nEpoch 27/100\\n1319/1319 - 0s - loss: 0.0642 - accuracy: 0.9826 - val_loss: 0.0244 - val_accuracy: 0.9879\\nEpoch 28/100\\n1319/1319 - 0s - loss: 0.0518 - accuracy: 0.9864 - val_loss: 0.0195 - val_accuracy: 0.9939\\nEpoch 29/100\\n1319/1319 - 0s - loss: 0.0453 - accuracy: 0.9894 - val_loss: 0.0206 - val_accuracy: 0.9909\\nEpoch 30/100\\n1319/1319 - 0s - loss: 0.0466 - accuracy: 0.9871 - val_loss: 0.0080 - val_accuracy: 0.9939\\nEpoch 31/100\\n1319/1319 - 0s - loss: 0.0453 - accuracy: 0.9886 - val_loss: 0.0208 - val_accuracy: 0.9939\\nEpoch 32/100\\n1319/1319 - 0s - loss: 0.0406 - accuracy: 0.9894 - val_loss: 0.0212 - val_accuracy: 0.9909\\nEpoch 33/100\\n1319/1319 - 0s - loss: 0.0405 - accuracy: 0.9871 - val_loss: 0.0174 - val_accuracy: 0.9939\\nEpoch 34/100\\n1319/1319 - 0s - loss: 0.0362 - accuracy: 0.9901 - val_loss: 0.0195 - val_accuracy: 0.9939\\nEpoch 35/100\\n1319/1319 - 0s - loss: 0.0384 - accuracy: 0.9886 - val_loss: 0.0157 - val_accuracy: 0.9939\\nEpoch 36/100\\n1319/1319 - 0s - loss: 0.0363 - accuracy: 0.9894 - val_loss: 0.0164 - val_accuracy: 0.9939\\nEpoch 37/100\\n1319/1319 - 0s - loss: 0.0319 - accuracy: 0.9924 - val_loss: 0.0169 - val_accuracy: 0.9939\\nEpoch 38/100\\n1319/1319 - 0s - loss: 0.0328 - accuracy: 0.9909 - val_loss: 0.0151 - val_accuracy: 0.9939\\nEpoch 39/100\\n1319/1319 - 0s - loss: 0.0295 - accuracy: 0.9909 - val_loss: 0.0095 - val_accuracy: 0.9939\\nEpoch 40/100\\n1319/1319 - 0s - loss: 0.0302 - accuracy: 0.9917 - val_loss: 0.0118 - val_accuracy: 0.9939\\nEpoch 41/100\\n1319/1319 - 0s - loss: 0.0286 - accuracy: 0.9932 - val_loss: 0.0100 - val_accuracy: 0.9939\\nEpoch 42/100\\n1319/1319 - 0s - loss: 0.0312 - accuracy: 0.9917 - val_loss: 0.0104 - val_accuracy: 0.9939\\nEpoch 43/100\\n1319/1319 - 0s - loss: 0.0284 - accuracy: 0.9932 - val_loss: 0.0140 - val_accuracy: 0.9939\\nEpoch 44/100\\n1319/1319 - 0s - loss: 0.0294 - accuracy: 0.9917 - val_loss: 0.0116 - val_accuracy: 0.9939\\nEpoch 45/100\\n1319/1319 - 0s - loss: 0.0283 - accuracy: 0.9932 - val_loss: 0.0105 - val_accuracy: 0.9939\\nEpoch 46/100\\n1319/1319 - 0s - loss: 0.0245 - accuracy: 0.9939 - val_loss: 0.0142 - val_accuracy: 0.9939\\nEpoch 47/100\\n1319/1319 - 0s - loss: 0.0246 - accuracy: 0.9924 - val_loss: 0.0092 - val_accuracy: 0.9939\\nEpoch 48/100\\n1319/1319 - 0s - loss: 0.0242 - accuracy: 0.9924 - val_loss: 0.0123 - val_accuracy: 0.9939\\nEpoch 49/100\\n1319/1319 - 0s - loss: 0.0231 - accuracy: 0.9939 - val_loss: 0.0114 - val_accuracy: 0.9939\\nEpoch 50/100\\n1319/1319 - 0s - loss: 0.0234 - accuracy: 0.9924 - val_loss: 0.0075 - val_accuracy: 0.9939\\nEpoch 51/100\\n1319/1319 - 0s - loss: 0.0231 - accuracy: 0.9932 - val_loss: 0.0107 - val_accuracy: 0.9939\\nEpoch 52/100\\n1319/1319 - 0s - loss: 0.0220 - accuracy: 0.9932 - val_loss: 0.0106 - val_accuracy: 0.9939\\nEpoch 53/100\\n1319/1319 - 0s - loss: 0.0218 - accuracy: 0.9932 - val_loss: 0.0103 - val_accuracy: 0.9939\\nEpoch 54/100\\n1319/1319 - 0s - loss: 0.0173 - accuracy: 0.9955 - val_loss: 0.0126 - val_accuracy: 0.9939\\nEpoch 55/100\\n1319/1319 - 0s - loss: 0.0200 - accuracy: 0.9947 - val_loss: 0.0106 - val_accuracy: 0.9939\\nEpoch 56/100\\n1319/1319 - 0s - loss: 0.0228 - accuracy: 0.9947 - val_loss: 0.0069 - val_accuracy: 0.9939\\nEpoch 57/100\\n1319/1319 - 0s - loss: 0.0181 - accuracy: 0.9947 - val_loss: 0.0061 - val_accuracy: 0.9939\\nEpoch 58/100\\n1319/1319 - 0s - loss: 0.0169 - accuracy: 0.9947 - val_loss: 0.0086 - val_accuracy: 0.9939\\nEpoch 59/100\\n1319/1319 - 0s - loss: 0.0193 - accuracy: 0.9947 - val_loss: 0.0074 - val_accuracy: 0.9939\\nEpoch 60/100\\n1319/1319 - 0s - loss: 0.0185 - accuracy: 0.9955 - val_loss: 0.0098 - val_accuracy: 0.9939\\nEpoch 61/100\\n1319/1319 - 0s - loss: 0.0200 - accuracy: 0.9955 - val_loss: 0.0099 - val_accuracy: 0.9939\\nEpoch 62/100\\n1319/1319 - 0s - loss: 0.0167 - accuracy: 0.9955 - val_loss: 0.0086 - val_accuracy: 0.9939\\nEpoch 63/100\\n1319/1319 - 0s - loss: 0.0172 - accuracy: 0.9955 - val_loss: 0.0087 - val_accuracy: 0.9939\\nEpoch 64/100\\n1319/1319 - 0s - loss: 0.0171 - accuracy: 0.9955 - val_loss: 0.0082 - val_accuracy: 0.9939\\nEpoch 65/100\\n1319/1319 - 0s - loss: 0.0156 - accuracy: 0.9962 - val_loss: 0.0098 - val_accuracy: 0.9939\\nEpoch 66/100\\n1319/1319 - 0s - loss: 0.0178 - accuracy: 0.9955 - val_loss: 0.0081 - val_accuracy: 0.9939\\nEpoch 67/100\\n1319/1319 - 0s - loss: 0.0154 - accuracy: 0.9947 - val_loss: 0.0063 - val_accuracy: 0.9939\\nEpoch 68/100\\n1319/1319 - 0s - loss: 0.0145 - accuracy: 0.9977 - val_loss: 0.0085 - val_accuracy: 0.9939\\nEpoch 69/100\\n1319/1319 - 0s - loss: 0.0152 - accuracy: 0.9970 - val_loss: 0.0093 - val_accuracy: 0.9939\\nEpoch 70/100\\n1319/1319 - 0s - loss: 0.0138 - accuracy: 0.9947 - val_loss: 0.0051 - val_accuracy: 0.9970\\nEpoch 71/100\\n1319/1319 - 0s - loss: 0.0152 - accuracy: 0.9955 - val_loss: 0.0062 - val_accuracy: 0.9939\\nEpoch 72/100\\n1319/1319 - 0s - loss: 0.0125 - accuracy: 0.9962 - val_loss: 0.0056 - val_accuracy: 0.9939\\nEpoch 73/100\\n1319/1319 - 0s - loss: 0.0131 - accuracy: 0.9955 - val_loss: 0.0068 - val_accuracy: 0.9939\\nEpoch 74/100\\n1319/1319 - 0s - loss: 0.0129 - accuracy: 0.9962 - val_loss: 0.0064 - val_accuracy: 0.9939\\nEpoch 75/100\\n1319/1319 - 0s - loss: 0.0109 - accuracy: 0.9970 - val_loss: 0.0052 - val_accuracy: 0.9970\\nEpoch 76/100\\n1319/1319 - 0s - loss: 0.0127 - accuracy: 0.9962 - val_loss: 0.0057 - val_accuracy: 0.9939\\nEpoch 77/100\\n1319/1319 - 0s - loss: 0.0117 - accuracy: 0.9962 - val_loss: 0.0048 - val_accuracy: 0.9970\\nEpoch 78/100\\n1319/1319 - 0s - loss: 0.0120 - accuracy: 0.9970 - val_loss: 0.0024 - val_accuracy: 1.0000\\nEpoch 79/100\\n1319/1319 - 0s - loss: 0.0124 - accuracy: 0.9962 - val_loss: 0.0040 - val_accuracy: 0.9970\\nEpoch 80/100\\n1319/1319 - 0s - loss: 0.0117 - accuracy: 0.9970 - val_loss: 0.0045 - val_accuracy: 0.9970\\nEpoch 81/100\\n1319/1319 - 0s - loss: 0.0098 - accuracy: 0.9985 - val_loss: 0.0020 - val_accuracy: 1.0000\\nEpoch 82/100\\n1319/1319 - 0s - loss: 0.0095 - accuracy: 0.9985 - val_loss: 0.0023 - val_accuracy: 1.0000\\nEpoch 83/100\\n1319/1319 - 0s - loss: 0.0086 - accuracy: 0.9985 - val_loss: 0.0033 - val_accuracy: 1.0000\\nEpoch 84/100\\n1319/1319 - 0s - loss: 0.0086 - accuracy: 0.9985 - val_loss: 0.0033 - val_accuracy: 1.0000\\nEpoch 85/100\\n1319/1319 - 0s - loss: 0.0086 - accuracy: 0.9977 - val_loss: 0.0027 - val_accuracy: 1.0000\\nEpoch 86/100\\n1319/1319 - 0s - loss: 0.0083 - accuracy: 0.9977 - val_loss: 0.0028 - val_accuracy: 1.0000\\nEpoch 87/100\\n1319/1319 - 0s - loss: 0.0084 - accuracy: 0.9985 - val_loss: 0.0064 - val_accuracy: 0.9939\\nEpoch 88/100\\n1319/1319 - 0s - loss: 0.0074 - accuracy: 0.9985 - val_loss: 0.0033 - val_accuracy: 1.0000\\nEpoch 89/100\\n1319/1319 - 0s - loss: 0.0073 - accuracy: 0.9977 - val_loss: 0.0023 - val_accuracy: 1.0000\\nEpoch 90/100\\n1319/1319 - 0s - loss: 0.0060 - accuracy: 0.9992 - val_loss: 0.0016 - val_accuracy: 1.0000\\nEpoch 91/100\\n1319/1319 - 0s - loss: 0.0070 - accuracy: 0.9985 - val_loss: 0.0014 - val_accuracy: 1.0000\\nEpoch 92/100\\n1319/1319 - 0s - loss: 0.0062 - accuracy: 0.9992 - val_loss: 0.0011 - val_accuracy: 1.0000\\nEpoch 93/100\\n1319/1319 - 0s - loss: 0.0047 - accuracy: 0.9992 - val_loss: 4.4620e-04 - val_accuracy: 1.0000\\nEpoch 94/100\\n1319/1319 - 0s - loss: 0.0044 - accuracy: 0.9992 - val_loss: 8.2091e-04 - val_accuracy: 1.0000\\nEpoch 95/100\\n1319/1319 - 0s - loss: 0.0046 - accuracy: 0.9992 - val_loss: 7.8273e-04 - val_accuracy: 1.0000\\nEpoch 96/100\\n1319/1319 - 0s - loss: 0.0067 - accuracy: 0.9985 - val_loss: 4.5473e-04 - val_accuracy: 1.0000\\nEpoch 97/100\\n1319/1319 - 0s - loss: 0.0047 - accuracy: 1.0000 - val_loss: 3.2954e-04 - val_accuracy: 1.0000\\nEpoch 98/100\\n1319/1319 - 0s - loss: 0.0037 - accuracy: 1.0000 - val_loss: 1.7737e-04 - val_accuracy: 1.0000\\nEpoch 99/100\\n1319/1319 - 0s - loss: 0.0037 - accuracy: 0.9992 - val_loss: 2.7643e-04 - val_accuracy: 1.0000\\nEpoch 100/100\\n1319/1319 - 0s - loss: 0.0028 - accuracy: 1.0000 - val_loss: 2.3306e-04 - val_accuracy: 1.0000\\nTest loss: 0.005438241473760299\\nTest accuracy: 1.0\\nmodel saved in ./outputs/model folder\\n2020-04-25 08:48:04.423950: I tensorflow/core/grappler/devices.cc:55] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0\\n2020-04-25 08:48:04.424041: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session\\n2020-04-25 08:48:04.425162: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:814] Optimization results for grappler item: graph_to_optimize\\n2020-04-25 08:48:04.425207: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816]   function_optimizer: function_optimizer did nothing. time = 0.001ms.\\n2020-04-25 08:48:04.425215: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816]   function_optimizer: function_optimizer did nothing. time = 0ms.\\n2020-04-25 08:48:04.459128: I tensorflow/core/grappler/devices.cc:55] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0\\n2020-04-25 08:48:04.459194: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session\\n2020-04-25 08:48:04.464540: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:814] Optimization results for grappler item: graph_to_optimize\\n2020-04-25 08:48:04.464560: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816]   constant_folding: Graph size after: 22 nodes (-6), 27 edges (-6), time = 2.671ms.\\n2020-04-25 08:48:04.464566: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:816]   constant_folding: Graph size after: 22 nodes (0), 27 edges (0), time = 0.981ms.\\n\\n\\nThe experiment completed successfully. Finalizing run...\\nLogging experiment finalizing status in history service.\\nStarting the daemon thread to refresh tokens in background for process with pid = 9\\nCleaning up all outstanding Run operations, waiting 300.0 seconds\\n2 items cleaning up...\\nCleanup took 0.14500951766967773 seconds\\nEnter __exit__ of DatasetContextManager\\nUnmounting /tmp/tmpgo81zb8r.\\nFinishing unmounting /tmp/tmpgo81zb8r.\\nExit __exit__ of DatasetContextManager\\nEngine process terminated with returncode=0\\n\\nRun is completed.\", \"graph\": {}, \"widget_settings\": {\"childWidgetDisplay\": \"popup\", \"send_telemetry\": false, \"log_level\": \"INFO\", \"sdk_version\": \"1.3.0\"}, \"loading\": false}"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from azureml.widgets import RunDetails\n",
    "RunDetails(run).show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best run ID: motor-activity-recognition-2_1587804446_be2a7838\n",
      "Best run accuracy: 1.0\n"
     ]
    }
   ],
   "source": [
    "best_run_id = None\n",
    "best_run_accuracy = None\n",
    "\n",
    "for run in exp.get_runs():\n",
    "    metrics = run.get_metrics()\n",
    "    details = run.get_details()\n",
    "    \n",
    "    run_id = details[\"runId\"]\n",
    "    \n",
    "    try:\n",
    "        accuracy = metrics[\"Final test accuracy\"]\n",
    "    except:\n",
    "        pass\n",
    "    \n",
    "    if best_run_accuracy is None:\n",
    "        best_run_accuracy = accuracy\n",
    "        best_run_id = run_id\n",
    "    else:\n",
    "        if accuracy > best_run_accuracy:\n",
    "            best_run_accuracy = accuracy\n",
    "            best_run_id = run_id\n",
    "\n",
    "print('Best run ID: {}'.format(best_run_id))\n",
    "print('Best run accuracy: {}'.format(best_run_accuracy))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Accuracy vs Loss_1587804484.png', 'azureml-logs/60_control_log.txt', 'azureml-logs/70_driver_log.txt', 'logs/azureml/9_azureml.log', 'outputs/model/model.h5', 'outputs/model/model.json', 'outputs/model/model.tflite']\n"
     ]
    }
   ],
   "source": [
    "from azureml.core import Run\n",
    "best_run = Run(experiment=exp, run_id=best_run_id)\n",
    "print(best_run.get_file_names())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "best_run.download_file(name=\"outputs/model/model.tflite\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6 - AzureML",
   "language": "python",
   "name": "python3-azureml"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
